import type { Config } from './type'
import axios from 'axios'

let curConfig: Config = {}

export async function getServerConfig() {
  return axios
    .get<Config>('config.json')
    .then(({ data }) => {
      curConfig = data
    })
    .catch(() => {
      throw new Error('请在public文件夹下添加config.json配置文件')
    })
}

export function getConfig() {
  return curConfig as Required<Config>
}
